unit gui_form_Tiatai;

{
  The first gui for this project, simple and based on forms. Made for windows, not tested elsewhere.
}

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Controls, Graphics, Dialogs, gui_form_basic, StateMachine,
  gui_form_Tiatai_Field, gui_form_Tiatai_main, gui_form_Tiatai_AISettings,
  gui_form_tiatai_output, gui_form_tiatai_Resources;

type
  { TTiatai }

  { TGUI_Form_Tiatai }

  TGUI_Form_Tiatai = class(TGUI_Form_Basic)
    private
      FFieldForm: TTTiatai_FieldForm;
      FMainForm: TTTiatai_MainForm;
      FAISettingForm: TTiatai_AISettings;
      FOutputForm: TTTiatai_OutputForm;
      FResourcesForm: TTTiatai_ResourcesForm;
    public
      constructor Create; override;
      destructor Destroy; override;
    public
      procedure UpdateGUI; override;
      procedure Show; override;
    protected
      procedure ShowField(Sender: TObject);
      procedure ShowAISettings(Sender: TObject);
      procedure ShowOutput(Sender: TObject);
      procedure ShowResources(Sender: TObject);
  end;

implementation

uses
  SystemManager;

constructor TGUI_Form_Tiatai.Create;
begin
  inherited Create;
  FMainForm  := TTTiatai_MainForm.Create(nil);
  FMainForm.OnFieldClick := @ShowField;
  FMainForm.OnAISettingsClick := @ShowAISettings;
  FMainForm.OnOutputClick := @ShowOutput;
  FMainForm.OnResourcesClick := @ShowResources;

  FFieldForm := TTTiatai_FieldForm.Create(FMainForm);
  FAISettingForm := TTiatai_AISettings.Create(FMainForm);
  FOutputForm := TTTiatai_OutputForm.Create(FMainForm);
  FResourcesForm := TTTiatai_ResourcesForm.Create(FMainForm);
end;

destructor TGUI_Form_Tiatai.Destroy;
begin
  FMainForm.Free;
  inherited Destroy;
end;

procedure TGUI_Form_Tiatai.UpdateGUI;
begin
  FFieldForm.UpdateInfos;
  FResourcesForm.UpdateInfos;
  if FMainForm.Closed then
  begin
    GlobalStateMachine.Transit(SS_SelectSystems);
  end;
end;

procedure TGUI_Form_Tiatai.Show;
begin
  FMainForm.Show;
end;

procedure TGUI_Form_Tiatai.ShowField(Sender: TObject);
begin
  FFieldForm.Show;
end;

procedure TGUI_Form_Tiatai.ShowAISettings(Sender: TObject);
begin
  FAISettingForm.Show;
end;

procedure TGUI_Form_Tiatai.ShowOutput(Sender: TObject);
begin
  FOutputForm.Show;
end;

procedure TGUI_Form_Tiatai.ShowResources(Sender: TObject);
begin
  FResourcesForm.Show;
end;

initialization
  GlobalSystemManager.RegisterGUISystem(TGUI_Form_Tiatai);

end.
